using System;
using System.Text;
using Com.ContentRendering.Api.ParserEngine.Exceptions;

namespace Com.ContentRendering.Api.ParserEngine.State
{
    /// <summary/>
    internal class RootTagState : AbstractNameState
    {
        /// <summary/>
        internal RootTagState(AbstractState state) : base(state) { }

        /// <summary/>
        protected override void ParseChildCharacter()
        {
            // has nothing been written to the attribute name
            if (base._stringBuilder.Length == 0)
            {
                // the state needs to be updated
                base._documentParser.State = new ChildTagState(this);
            }
            else
            {
                throw new TagNameInvalidException();
            }
        }

        /// <summary/>
        protected override void ParseParentCharacter()
        {
            // has nothing been written to the attribute name
            if (base._stringBuilder.Length == 0)
            {
                // the state needs to be updated
                base._documentParser.State = new ParentTagState(this);
            }
            else
            {
                throw new TagNameInvalidException();
            }
        }

        /// <summary/>
        protected override OutputNodeInterface AddSubstitutionTag()
        {
            return base._outputNode.AddRootSubstitutionTag(base._stringBuilder.ToString());
        }

        /// <summary/>
        protected override OutputNodeInterface AddTransparentTag()
        {
            return base._outputNode.AddRootTransparentTag(base._stringBuilder.ToString());
        }

        /// <summary/>
        protected override OutputNodeInterface AddIfTag()
        {
            return base._outputNode.AddRootIfTag(base._stringBuilder.ToString());
        }

        /// <summary/>
        protected override OutputNodeInterface AddIfNotTag()
        {
            return base._outputNode.AddRootIfNotTag(base._stringBuilder.ToString());
        }

        /// <summary/>
        protected override void AddOutputTag()
        {
            base._outputNode.AddRootOutputTag(base._stringBuilder.ToString());
        }
    }
}
